package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.model.admin.log.SysLog;
import com.zhentao.model.admin.log.param.LogParam;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.model.common.enums.AppHttpCodeEnum;
import com.zhentao.service.SysLogService;
import com.zhentao.mapper.SysLogMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author lenovo
* @description 针对表【sys_log(系统日志)】的数据库操作Service实现
* @createDate 2025-01-02 15:30:04
*/
@Service
@Slf4j
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog>
    implements SysLogService{

    @Autowired
    private SysLogMapper sysLogMapper;

    /**
     * @description  日志查询
     * @author 振涛教育_小Q
     * @date    2025/1/2 15:33
     * @param
     * @return com.zhentao.model.common.dtos.ResponseResult
     */
    @Override
    public ResponseResult logList(LogParam logParam) {
        // 分页
        Page<SysLog> page = new Page<>(logParam.getPageNum(), logParam.getPageSize());

        this.page(page, Wrappers.<SysLog>lambdaQuery()
                .orderByDesc(SysLog::getCreateTime));
        return ResponseResult.okResult(page);
    }

    /**
     * @description  清空日志
     * @author 振涛教育_小Q
     * @date    2025/1/2 18:59
     * @param
     * @return com.zhentao.model.common.dtos.ResponseResult
     */
    @Override
    public ResponseResult clearLog() {
        log.info("清空日志开始---------------");
        try {
            sysLogMapper.clearLog();
        } catch (Exception e) {
            throw new RuntimeException("clear log exception");
        }
        log.info("清空日志结束---------------");
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}




